const arrUnitSecond = [60 * 60 * 24 * 365, 60 * 60 * 24, 60 * 60, 60, 1];
const arrUnitText = ['年', '天', '时', '分', '秒'];

global.tadd = (time, value, unit = 's') => M(time).add(value, unit).format();
global.tiff = (timeA, timeB, unit = 's') => M(timeA).diff(M(timeB), unit);
global.tiffText = (timeA, timeB, range = 2) => {
	const ma = M(timeA);
	const mb = M(timeB);

	let diff = Math.abs(ma.diff(mb, 's', true));
	let result = '';

	let rangeUnit = range;
	for(let i = 0; i < arrUnitText.length; i++) {
		const threshold = arrUnitSecond[i];

		let count = 0;
		while(diff > threshold) {
			diff -= threshold;
			count++;
		}

		if(count) {
			result += `${count}${arrUnitText[i]}`;

			if(!--rangeUnit) {
				break;
			}
		}
	}

	return result || '0秒！！！！';
};